package com.iweb.newa202104.config;

/**
 * description:  <br>
 * date: 2021/5/16 18:35 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 */

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String uploadPath;

    @Value("${upload.farm}")
    private String farmPath;

    @Value("${upload.farm-static}")
    private String farmStatic;

    @Value("${upload.miner}")
    private String miner;

    @Value("${upload.miner-public}")
    private String minerPublic;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * 访问路径：http://localhost:93/facereport/static/captured/daping_report/captured_images/face/788001414206074880/2021/1/27/cj_142207194912440320.png
         * "/facereport/static/captured/**" 为前端URL访问路径
         * "file:" + uploadPath 是本地磁盘映射
         */
        registry.addResourceHandler("/file/**").addResourceLocations("file:" + uploadPath);
        registry.addResourceHandler("/farm/**").addResourceLocations("file:" + farmPath);
        registry.addResourceHandler("/static/**").addResourceLocations("file:" + farmStatic);
        registry.addResourceHandler("/Miner/**").addResourceLocations("file:" + miner);
        registry.addResourceHandler("/public/**").addResourceLocations("file:" + minerPublic);
    }

}

